home *** CD-ROM | disk | FTP | other *** search
- szTitle = "ClockMan GetTime pgm"
- bOK = @TRUE
- szDial = "%dialupname%"
- szHost = "%timeserveraddr%"
- szErrDesc = ""
-
-
- ;Dial our host (unless user is on a direct connect)...
- hConn = 0
- if (szDial <> "")
- hConn = SDialUp (szDial)
- nErr = SGetLastErr ()
- if (!hConn)
- switch nErr
- case @SErrNotFound
- szErrDesc = "Couldn't connect to %szDial% - no such dial-up"
-
- case nErr ; <--default
- szErrDesc = "Couldn't connect to %szDial% - error %nErr%"
- endswitch
- bOK = @FALSE
- goto LogIt
- endif
- endif
-
- ; Create a socket...
- hSock = SOpen (@SBlocking)
- if (hSock==@SErrSocket)
- nErr = SGetLastErr ()
- szErrDesc = "Couldn't create socket - error %nErr%"
- bOK = @FALSE
- goto HangUp
- endif
-
- ; Connect it up...
- nRet = SConnect (hSock, szHost, "time")
- if (nRet <> @TRUE)
- nErr = SGetLastErr ()
- switch nErr
- case @SErrHostName
- szErrDesc = "Host ""%szHost%"" not found. (Misspelled, or no longer exists.)"
- break
-
- case 10060
- szErrDesc = "Timed out trying to connect to ""%szHost%""."
- break
-
- case @SErrBusy
- szErrDesc = "Couldn't connect to ""%szHost%"".%@CRLF%(Server busy.)"
- break
-
- case @SErrNoConn
- szErrDesc = "Couldn't connect to ""%szHost%"".%@CRLF%(Server down, or they don't offer a time server.)"
- break
-
- case nErr ; <--default
- szErrDesc = "Couldn't connect to ""%szHost%"" - WinSock error %nErr%"
- endswitch
-
- bOK = @FALSE
- goto CloseSocket
- endif
-
- ; Time server sent us the time immediately upon connect...
- dwRawTime = SRecvNum32 (hSock)
- dwPrevTime = CMGetSysTime ()
- if (!dwRawTime)
- ; Oh, maybe they require a CR/LF first like RFC 868 claims they should?...
- SSendLine (hSock, "")
- dwRawTime = SRecvNum32 (hSock)
- dwPrevTime = CMGetSysTime ()
- endif
-
- if (!dwRawTime)
- szErrDesc = "No response from time server @ ""%szHost%""."
- bOK = @FALSE
- else
- ; Immediately update our system time...
- dwNewTime = dwRawTime - 2208988800; Convert to secs since 1/1/70 from 1/1/00
- CMSetSysTime (dwNewTime)
- endif
-
- ; If user hit Ctrl+Break, WIL will bring us here...
- :Cancel
-
- ; Close the socket...
- :CloseSocket
- nRet = SClose (hSock)
-
- ; Hang up...
- :HangUp
- if (hConn)
- nRet = SHangUp (hConn)
- endif
-
-
- ; Log what we did...
- :LogIt
- if bOK == @TRUE
- ; Finally, log the adjustment...
- dwOffset = dwNewTime - dwPrevTime
- if (dwOffset > 0)
- szLog = "Turned the clock forward by %dwOffset% seconds"
- else
- if (dwOffset < 0)
- dwOffset = -dwOffset
- szLog = "Turned the clock back by %dwOffset% seconds"
- else
- szLog = "No adjustment needed to the system clock!"
- endif
- endif
- else
- szLog = strcat ("Error attempting to adjust time:", @CRLF, szErrDesc)
- endif
-
- CMLogMessage (szLog)
- Display (5, szTitle, szLog)
- ~
-